package com.psp.bu.netease;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Test {

	public void AddFriend() {
		NeteaseManager aa = new NeteaseManager(NeteaseManager.appKey, NeteaseManager.appSecret);
		aa.addFriend("serviceCategory1", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory2", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory3", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory4", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory5", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory6", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
		aa.addFriend("serviceCategory7", "800f6b8d71dc4995970b9d60cd1875af", 1, null);
	}

	public void testUpdateAccount() {
		NeteaseManager aa = new NeteaseManager(NeteaseManager.appKey, NeteaseManager.appSecret);
		aa.updateUinfo("serviceCategory1", "敏捷制造 快制中心", "http://qnimg.zpark-imway.com/ArtboardCopy1.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory2", "产品创意 工业设计 ", "http://qnimg.zpark-imway.com/ArtboardCopy2.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory3", "技术研发 方案设计", "http://qnimg.zpark-imway.com/ArtboardCopy3.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory4", "检测检验 标准认证", "http://qnimg.zpark-imway.com/ArtboardCopy4.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory5", "产品中试 中小批量", "http://qnimg.zpark-imway.com/ArtboardCopy5.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory6", "协同创新 科技服务", "http://qnimg.zpark-imway.com/ArtboardCopy6.png#", null, null,
				null, null, null, null);
		aa.updateUinfo("serviceCategory7", "市场推广 品牌提升", "http://qnimg.zpark-imway.com/ArtboardCopy7.png#", null, null,
				null, null, null, null);
	}

	public static void main(String[] args) throws Exception {
		DefaultHttpClient httpClient = new DefaultHttpClient();
		String url = "https://api.netease.im/nimserver/user/create.action";
		HttpPost httpPost = new HttpPost(url);

		String appKey = "0122e119de19a63125fd1de683bc9503";
		String appSecret = "f4300b0489af";
		String nonce = "123456";
		String curTime = String.valueOf((new Date()).getTime() / 1000L);
		String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime);// 参考
																					// 计算CheckSum的java代码

		// 设置请求的header
		httpPost.addHeader("AppKey", appKey);
		httpPost.addHeader("Nonce", nonce);
		httpPost.addHeader("CurTime", curTime);
		httpPost.addHeader("CheckSum", checkSum);
		httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

		// 设置请求的参数
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		// nvps.add(new BasicNameValuePair("accid", "serviceCategory2"));
		// nvps.add(new BasicNameValuePair("name", "技术研发 方案设计"));
		// nvps.add(new BasicNameValuePair("token",
		// "7B1BE2F43FA64321FE9BF8CEFB4ABCC1"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory1"));
		// nvps.add(new BasicNameValuePair("name", "敏捷制造 快制中心"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory3"));
		// nvps.add(new BasicNameValuePair("name", "王抗抗"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory4"));
		// nvps.add(new BasicNameValuePair("name", "杜雨飞"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory5"));
		// nvps.add(new BasicNameValuePair("name", "王磊"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory6"));
		// nvps.add(new BasicNameValuePair("name", "周瑞新"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "servicecategory61"));
		// nvps.add(new BasicNameValuePair("name", "协同创新 科技服务"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "servicecategory62"));
		// nvps.add(new BasicNameValuePair("name", "协同创新 科技服务"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		// nvps.add(new BasicNameValuePair("accid", "serviceCategory7"));
		// nvps.add(new BasicNameValuePair("name", "王欣"));
		// nvps.add(new BasicNameValuePair("token", "123456"));

		httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

		// 执行请求
		HttpResponse response = httpClient.execute(httpPost);

		// 打印执行结果
		System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
	}
}